﻿using System.Collections.Generic;
using Animoso.Domain;
using Animoso.Domain.Data;
using NHibernate;
using NHibernate.Criterion;

namespace Animoso.Data
{
    public class NewsItemRepository : BaseRepository<NewsItem>, INewsItemRepository
    {
        public IEnumerable<NewsItem> GetLatestNewsItems(int count)
        {
            using (ISession session = SessionProvider.GetSession())
                return session.CreateCriteria(typeof(NewsItem)).SetFetchSize(count)
                    .Add(Expression.Eq("Published", true))
                    .AddOrder(Order.Desc("DateTime"))
                    .List<NewsItem>();           
        }
    }
}
